package cloud.maque.module.system.controller;

import cloud.maque.common.core.request.PageRequest;
import cloud.maque.common.core.response.R;
import cloud.maque.module.system.entity.SysUser;
import cloud.maque.module.system.extend.UserExtendSerivce;
import cloud.maque.module.system.model.UserDto;
import cloud.maque.module.system.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户接口
 */
@Tag(name = "用户管理接口")
@RestController
@RequestMapping(value = "/user")
public class UserController {


    @Autowired
    UserService userService;

    @Autowired
    UserExtendSerivce userExtendSerivce;


    @Operation(summary = "用户列表")
    @PostMapping("/list")
    public R<List<SysUser>> List(@RequestBody PageRequest<SysUser> pageReq) {

        return R.ok("OK", userService.GetList(pageReq));
    }

    @Operation(summary = "用户详情")
    @GetMapping("/get/{userId}")
    public R<UserDto> GetOne(@PathVariable("userId") String userId) {
        return R.ok("OK", userExtendSerivce.GetUserFullInfo(userId));
    }

    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public R<UserDto> Register(@RequestBody UserDto data) {
        return R.ok("OK", userExtendSerivce.RegUser(data));
    }


    @Operation(summary = "用户编辑")
    @PostMapping("/edit-save")
    public R<UserDto> EditSave(@RequestBody UserDto data) {
        return R.ok("OK", userExtendSerivce.EditUser(data));
    }


    @Operation(summary = "用户删除,逻辑删除")
    @DeleteMapping("/delete/{id}")
    public R<Boolean> Delete(@PathVariable("id") String id) {
        return R.ok("OK", userService.DeleteUser(id));
    }
}
